package com.wannengbang.storemobile.homepage.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.storemobile.R;
import com.wannengbang.storemobile.bean.StoreListBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 消息列表
 */
public class SelectStoreListAdapter extends RecyclerView.Adapter<SelectStoreListAdapter.ViewHolder> {

    private List<StoreListBean.DataBean.ItemListBean> listsBeans;
    private Context context;
    private onCallBackListener onCallBackListener;
    private String store_no;

    public SelectStoreListAdapter(List<StoreListBean.DataBean.ItemListBean> listsBeans, String store_no) {
        this.listsBeans = listsBeans;
        this.store_no = store_no;
    }

    public void setOnCallBackListener(SelectStoreListAdapter.onCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_select_store_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        StoreListBean.DataBean.ItemListBean dataBean = listsBeans.get(position);
        int channel_type = dataBean.getChannel_type();

        if (channel_type==2){
            holder.tv_channel_type.setText("智能版");
        }else {
            holder.tv_channel_type.setText("标准版");
        }

        holder.tvStoreName.setText(dataBean.getName());

        if (dataBean.getStore_no().equals(store_no)) {
            holder.iv_select.setImageResource(R.mipmap.ic_order_xuanze);
        } else {
            holder.iv_select.setImageResource(R.mipmap.ic_order_kongyuan);
        }
        holder.itemView.setOnClickListener(v -> {
            onCallBackListener.onCallBack(position);
        });
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_store_name)
        TextView tvStoreName;
        @BindView(R.id.tv_channel_type)
        TextView tv_channel_type;
        @BindView(R.id.iv_select)
        ImageView iv_select;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface onCallBackListener {
        void onCallBack(int position);
    }
}
